package com.example.emos.workflow.service.impl;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.example.emos.workflow.common.EmosException;
import com.example.emos.workflow.db.dao.TbMeetingDao;
import com.example.emos.workflow.service.MeetingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @Description: //todo
 * @Author: 张广焱
 * @Date: 2024-05-26 下午6:33
 */
@Service
public class MeetingServiceImpl implements MeetingService {
    @Resource
    private TbMeetingDao tbMeetingDao;

    @Override
    public void updateMeetingStatus(HashMap param) {
        int rows = tbMeetingDao.updatemeetingStatus(param);
        if (rows != 1) {
            throw new EmosException("会议状态更新失败");
        }
    }

    @Override
    public HashMap searchMeetingByInstanceId(String instanceId) {
        HashMap map = tbMeetingDao.searchMeetingByInstanceId(instanceId);
        //以下功能是给小程序项目用的，每个会议申请中都会显示会议时长为几小时
        String date = map.get("date").toString();
        String start = map.get("start").toString();
        DateTime startDate = DateUtil.parse(date + " " + start, "yyyy-MM-dd HH:mm");
        String end = map.get("end").toString();
        DateTime endDate = DateUtil.parse(date + " " + end, "yyyy-MM-dd HH:mm");
        long hours = DateUtil.between(endDate, startDate, DateUnit.HOUR, true);
        map.put("hours", hours);
        return map;
    }

    @Override
    public HashMap searchMeetingByUUID(String uuid) {
        return tbMeetingDao.searchMeetingByUUID(uuid);
    }
}


